﻿Imports System
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Drawing
Imports System.Drawing.Design
Imports System.Runtime.InteropServices
Imports System.Workflow.ComponentModel
Imports System.Workflow.ComponentModel.Compiler
Imports System.Workflow.ComponentModel.Design

Namespace System.Workflow.Activities
    <SRDescription("SetStateActivityDescription"), ComVisible(False), SRCategory("Standard"), ActivityValidator(GetType(SetStateValidator)), ToolboxItem(GetType(ActivityToolboxItem)), Designer(GetType(SetStateDesigner), GetType(IDesigner)), ToolboxBitmap(GetType(SetStateActivity), "Resources.SetStateActivity.png")> _
    Public NotInheritable Class SetStateActivity
        Inherits Activity
        ' Methods
        Public Sub New()
        End Sub

        Public Sub New(ByVal name As String)
            MyBase.New(name)
        End Sub

        Protected Overrides Function Execute(ByVal executionContext As ActivityExecutionContext) As ActivityExecutionStatus
            If (executionContext Is Nothing) Then
                Throw New ArgumentNullException("executionContext")
            End If
            StateMachineExecutionState.Get(StateMachineHelpers.GetRootState(StateMachineHelpers.FindEnclosingState(executionContext.Activity))).NextStateName = Me.TargetStateName
            Return ActivityExecutionStatus.Closed
        End Function


        ' Properties
        <SRDescription("TargetStateDescription"), Editor(GetType(StateDropDownEditor), GetType(UITypeEditor)), DefaultValue(CStr(Nothing))> _
        Public Property TargetStateName As String
            Get
                Return [TryCast](MyBase.GetValue(SetStateActivity.TargetStateNameProperty),String)
            End Get
            Set(ByVal value As String)
                MyBase.SetValue(SetStateActivity.TargetStateNameProperty, value)
            End Set
        End Property


        ' Fields
        Public Shared ReadOnly TargetStateNameProperty As DependencyProperty = DependencyProperty.Register("TargetStateName", GetType(String), GetType(SetStateActivity), New PropertyMetadata("", DependencyPropertyOptions.Metadata, New Attribute() { New ValidationOptionAttribute(ValidationOption.Optional) }))
        Friend Const TargetStateNamePropertyName As String = "TargetStateName"
    End Class
End Namespace

